/*
Kiwi Editor is a framework for building WYSIWYG web editors.
Copyright (C) 2011  Roosevelt de Lima Sardinha

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

Contact the author at roosevelt1@gmail.com (Roosevelt) 
*/

/* Form Textbox */
function formTextbox(){	
    this.showProperties = function(){
	   this.tabId = this.propertyBox.addTab("Form Textbox");
   	   this.propertyBox.addProperty(this.tabId, 0, 0, 'name', 'Textbox', this, {
	   		label: 'Name',
			help: 'Sets an identifier of the textbox.'
	   });
	   this.propertyBox.addProperty(this.tabId, 1, 0, 'value', 'Textbox', this, {
	   		label: 'Content',
			help: 'Sets the content of the textbox.'
	   });
	   this.propertyBox.addProperty(this.tabId, 2, 0, 'label', 'Textbox', this, {
	   		label: 'Label',
			help: 'Sets the label of the textbox.'
	   });
	   
 	   this.propertyBox.addProperty(this.tabId, 3, 0, 'width', 'Textbox', this, {
	   		label: 'Width',
			help: 'Sets the width of the textbox.'
	   });
	   
   	   this.propertyBox.addProperty(this.tabId, 0, 2, 'left', 'Textbox', this, {
	   		label: 'Left',
			help: 'Sets the left coordinate of the textbox + label.'
	   });

	   this.propertyBox.addProperty(this.tabId, 1, 2, 'top', 'Textbox', this, {
	   		label: 'Top',
			help: 'Sets the top coordinate of the textbox + label.'
	   });	
	   

    };
    
    this.setProperty = function(property, value){
        // Changes the property of  this object setting it to value.
		 switch (property) {
			case 'name':
				this.textbox.name = value;
				break;
            case 'label':
                this.label.innerHTML = value;
                break;
            case 'value':
                this.textbox.value = value;
                break;
            case 'width':
                if (parseInt(value) < document.getElementById(this.EOM.editionArea.parentId).offsetWidth) {
                    this.textbox.style.width = value;
                    this.EOM.correctPosition(this.id);
                }
                break;
            case 'height':
                this.textbox.style.height = value;
                this.EOM.correctPosition(this.id);
                break;
            default:
                break;
        }
    };
    
    this.getProperty = function(property){
        // Gets the property of  this object
        switch (property) {
			case 'name':
				return this.textbox.name;
				break;
            case 'value':
                return this.textbox.value;
                break;
			case 'label':
				return this.label.innerHTML;
                break;
            case 'width':
                return this.textbox.style.width;
                break;
            case 'height':
                return this.textbox.style.width;
                break;
            default:
                break;
        }
    };
    
    this.JSON = function(){
        var EO_JSON = {
			name: this.getProperty('name'),
            label: this.getProperty('label'),
            value: this.getProperty('value'),
            width: this.getProperty('width'),
			height: this.getProperty('height')
		};
        return EO_JSON;
    }
	
	this.HTML = function(){
		var html = "<div style=\"top:" + this.getProperty('top') +"; left:" + this.getProperty('left') + "; position: absolute; \"><label>" + this.getProperty('label') + "</label>" +
		"<input type=\"textbox\" name=\"" + this.getProperty('name') + "\" value=\""+ this.getProperty('value')+ "\"  style=\"width:" + this.getProperty('width') + "; \" /></div>";
		return html;
	}
    
    this.help = "";
	
	this.objectList = new Array();
	this.selectorList = new Array();
	
    this.init = function(){        
        var objectList = new Array;
		objectList.push('div');
		
        this.objectList = objectList;
        
        var textbox = document.createElement('input');
        textbox.type = 'text';
        textbox.value = '';
        textbox.readOnly = true;
        textbox.value = 'Textbox';
		textbox.style.cursor = 'move';
        this.textbox = textbox;
		
		var label = document.createElement('label');
		label.innerHTML = 'Label: ';
		label.style.cursor = 'move';
		this.label = label;
		
		
		var div = document.createElement('div');
		div.appendChild(label);
		div.appendChild(textbox);
		
		this.div = div;
		
		var selectorList = new Array;
		
		selectorList.push('textbox');
		selectorList.push('label');
		
		this.selectorList = selectorList; 	
    }
}
